(function( pd ) {
	/*
	if ( pd.pform.PFC_AjaxFileUpload !== undefined ) {
		$.error( '$.pd.pform.PFC_AjaxFileUpload namespace already used' );
		return false;
	}
	*/
	pd.pform.PFC_AjaxFileUpload = {};
	// PFC_AjaxFileUpload constructor
	pd.pform.PFC_AjaxFileUpload = function(form, name, htmlName, htmlId, idFormForSubmit, onSuccess, onError, extraDataProducer, autoUpload) {
		this.form				= form;
		this.name 				= name;
		this.htmlName 			= htmlName;
		this.htmlId				= htmlId;
		this.idFormForSubmit	= idFormForSubmit;
		this.onSuccess 			= onSuccess;
		this.onError 			= onError;
		this.extraDataProducer 	= extraDataProducer;
		this.autoUpload 		= autoUpload;
		
		
		this.idUploadForm 		= this.form.name + "_" + this.name + "_form";
		this.idUploadIframe 	= this.form.name + "_" + this.name + "_iframe";
		
		var outerObj			= this;
		
		this.setForm = function(form) {
			outerObj.form = form;
		};
		
		this.getForm = function() {
			return outerObj.form;
		};
		
		
		
		this.startUpload = function() {
			var file = $("#" + htmlId);
			//$("#" + htmlId).attr("disabled", "disabled");
			$("#" + outerObj.idFormForSubmit).submit();
			var wrapper = $("<div>")
            .css({
                "width": file.width() + "px",
                "height": file.height() + "px",
                "display": "inline",
                "position": "absolute",
                "overflow": "hidden",
                "border":"1px solid red"
            });			
			
			//$("#" + htmlId).wrap(wrapper);
			//console.log($("#" + htmlId).position());
			return;
			var fileName= $("#" + outerObj.htmlId).val();
			var origClone 	= $("#" + outerObj.htmlId).clone(true, true);
			var origPos     = $("#" + outerObj.htmlId).position();
			var origParent 	= $("#" + outerObj.htmlId).parent();
			
			$("#" + outerObj.form.name).parent().append($("#" + outerObj.htmlId));
			//origClone.val($("#" + outerObj.htmlId).val());
			origParent.html(fileName);
			alert(fileName);
			return;
			//$(origClone).position(pos);
			
			
			var fname 	 = $("#" + outerObj.htmlId).val(); 
			var cloneElm = $("#" + outerObj.htmlId).clone();
			
			var obj = $(cloneElm);
			obj.val("aa");
			console.log($(cloneElm));
			//return;
			//alert(clone.toString());
			//$(clone).val(fname);
			
			$("#" + outerObj.form.name).parent().append(cloneElm);
			//alert();
			
			//$("#" + outerObj.idFormForSubmit).submit();
			return;
			var absolutePos	= $("#" + outerObj.htmlId).offset();
			
			$("#" + outerObj.idUploadForm).remove();
			$("#" + outerObj.idUploadIframe).remove();
			
			var newForm 	= '<form style="height:0px; width:0px;" target="' + outerObj.idUploadIframe + '" id="' + outerObj.idUploadForm + '" method="post" enctype="multipart/form-data" action="' + outerObj.form.backendUrl + "/?form-name=" + outerObj.form.name + "&service=ajax-file-upload" + '"></form>';
			var newIframe 	= '<iframe id="' + outerObj.idUploadIframe + '" name="' + outerObj.idUploadIframe + '" style="display:" id="" name=""></iframe>';
			
			$("#" + outerObj.form.name).parent().append(newForm);
			$("#" + outerObj.form.name).parent().append(newIframe);
			
			var clone 		= $("#" + outerObj.htmlId).clone();
			var cloneParent = $("#" + outerObj.htmlId).parent();
			
			
			$("#" + outerObj.idUploadForm).append($("#" + outerObj.htmlId));
			$("#" + outerObj.htmlId).offset({top:absolutePos.top, left:absolutePos.left});
			
			
			$("#" + outerObj.idUploadForm).submit();
		};
		
		this.fileSubmitResult = function() {
		};
	};
})( jQuery.pd );
